﻿using GrayParrot.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Test.DAL;

namespace Dashboard.BL.Facades
{
    public class TestFacade : FacadeBase<TestFacade>
    {
        NorthWindContext m_ctx = null;

        public TestFacade()
        {

        }

        public override void Initialize()
        {
            m_ctx = new NorthWindContext();
            m_ctx.Configuration.LazyLoadingEnabled = false;
            m_ctx.Configuration.ProxyCreationEnabled = false;
        }

        public override void Dispose()
        {
            if (m_ctx != null)
            {
                m_ctx.Dispose();
            }
        }

        public List<NameValue<string, int>> GetShippers()
        {
            List<NameValue<string, int>> retValue = null;

            var objs = from x in m_ctx.Shippers
                       select new NameValue<string, int>
                       {
                           name = x.CompanyName,
                           value = x.ShipperId
                       };

            if (objs.Any())
            {
                retValue = objs.ToList();
            }

            return retValue;
        }
    }
}